package com.gzc.just.play.last.war.sceneserver.gameobject.base;

import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 位置坐标类 - 表示游戏世界中的一个位置
 * 
 * @author AI Assistant
 * @version 1.0.0
 * @since 2025-11-22
 */
@Data
@NoArgsConstructor
public class Position {
    private double x;  // X坐标
    private double y;  // Y坐标
    private double z;  // Z坐标
    
    /**
     * 构造函数
     */
    public Position(double x, double y, double z) {
        this.x = x;
        this.y = y;
        this.z = z;
    }
    
    /**
     * 获取X坐标
     */
    public double getX() {
        return x;
    }
    
    /**
     * 获取Y坐标
     */
    public double getY() {
        return y;
    }
    
    /**
     * 获取Z坐标
     */
    public double getZ() {
        return z;
    }
    
    /**
     * 设置X坐标
     */
    public void setX(double x) {
        this.x = x;
    }
    
    /**
     * 设置Y坐标
     */
    public void setY(double y) {
        this.y = y;
    }
    
    /**
     * 设置Z坐标
     */
    public void setZ(double z) {
        this.z = z;
    }

    /**
     * 计算到另一个位置的距离
     */
    public double distance(Position other) {
        if (other == null) {
            return 0;
        }
        double dx = this.x - other.x;
        double dy = this.y - other.y;
        double dz = this.z - other.z;
        return Math.sqrt(dx * dx + dy * dy + dz * dz);
    }

    /**
     * 计算到另一个位置的方向向量
     */
    public Vector3 directionTo(Position other) {
        if (other == null) {
            return new Vector3(0, 0, 0);
        }
        double dx = other.x - this.x;
        double dy = other.y - this.y;
        double dz = other.z - this.z;
        double dist = Math.sqrt(dx * dx + dy * dy + dz * dz);
        if (dist == 0) {
            return new Vector3(0, 0, 0);
        }
        return new Vector3((float)(dx / dist), (float)(dy / dist), (float)(dz / dist));
    }

    /**
     * 检查是否在范围内
     */
    public boolean isWithinRange(Position other, double range) {
        return distance(other) <= range;
    }

    @Override
    public String toString() {
        return String.format("Position{x=%.2f, y=%.2f, z=%.2f}", x, y, z);
    }
}
